/*
 * NoScript - a Firefox extension for whitelist driven safe JavaScript execution
 *
 * Copyright (C) 2005-2024 Giorgio Maone <https://maone.net>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

(async () => {
  let [domain, tabId] = decodeURIComponent(location.hash.replace("#", "")).split(";");
  const BASE =  "https://noscript.net";
  await include([
   '/nscl/lib/punycode.js',
   '/nscl/common/Storage.js'
  ]);
  let {siteInfoConsent} = await Storage.get("sync", "siteInfoConsent");
  if (!siteInfoConsent) {
    await include('/nscl/common/locale.js');
    siteInfoConsent = confirm(_("siteInfo_confirm", [domain, BASE]));
    if (siteInfoConsent) {
      await Storage.set("sync", {siteInfoConsent});
    } else {
      let current = await browser.tabs.getCurrent();
      await browser.tabs.update(parseInt(tabId), {active: true});
      await browser.tabs.remove(current.id);
      return;
    }
  }
  let ace  = punycode.toASCII(domain);
  location.href = `${BASE}/about/${domain};${ace}`;
})();
